package com.java1412.controller;

import com.java1412.entity.User;
import com.java1412.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author java1412
 * @create 2021-07-15 14:13
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 保存用户
     *
     * @param user
     * @return
     */
    @PostMapping(value = "/save")
    public User save(@RequestBody User user) {
        return userService.saveUser(user);
    }

    /**
     * 根据用户名查用户
     *
     * @param username
     * @return
     */
    @GetMapping(value = "/{username}")
    public User findUser(@PathVariable String username) {
        return userService.findByUsername(username);
    }
}
